package com.photoeditor.demo.model.subscribe.manager;

import android.text.TextUtils;

import com.common.base.ComponentContext;
import com.photoeditor.R;
import com.photoeditor.demo.model.subscribe.strategy.SkuStrategyBean;
import com.photoeditor.demo.model.subscribe.strategy.SkuStrategyManager;

/**
 * Created by Lee on 2018/9/27.
 */

public class SkuManager {

    public final static int TYPE_ALL = 2001;
    public final static int TYPE_MONTHLY = 2002;
    public final static int TYPE_YEARLY = 2003;

    public final static String TYPE_MONTH = "month";
    public final static String TYPE_ANNUAL = "annual";

    public  static String SKU_MONTHLY_NORMAL = "iphotoeditor_monthly1999";
    public  static String SKU_YEARLY_NORMAL = "iphotoeditor_annual8099";

    public static SkuStrategyBean.SkuStrategyBeanConfig skuConfig;
    private static String monthType;
    private static String annualType;

    public static String[] getSkuInfo(int type) {
        String content = "";
        //得到sku策略
        skuConfig = SkuStrategyManager.getSkuStrategyConfig();
        monthType = skuConfig.getMonthType();
        annualType = skuConfig.getAnnualType();
        switch (type) {
            case TYPE_MONTHLY:
                content = monthType;
                break;
            case TYPE_YEARLY:
                content = annualType;
                break;
            case TYPE_ALL:
                content += monthType + "|";
                content += annualType;
                break;
            default:
                break;
        }
        if (!TextUtils.isEmpty(content)) {
            return content.split("\\|");
        }
        return null;
    }

    public static String getSkuInfoLast(int type) {
        String[] skus = getSkuInfo(type);
        if (skus == null || skus.length == 0 || TextUtils.isEmpty(skus[skus.length - 1])) {
            return null;
        }
        return skus[skus.length - 1];
    }

    //返回免费使用天数
    public static String getVipFreeDays(int type) {
        String price = "";
        switch (type) {
            case TYPE_MONTHLY:
                price = getString(R.string.vip_free_day_monthly);
                break;
            case TYPE_YEARLY:
                price = getString(R.string.vip_free_day_yearly);
                break;
        }
        return price;
    }

    public static String getVipPriceBMonth() {
        return getString(R.string.vip_price_b_month);
    }

    public static String getVipPriceBYear() {
        return getString(R.string.vip_price_b_year);
    }

    private static String getString(int id) {
        return ComponentContext.getContext().getResources().getString(id);
    }

}
